package com.lcb.jmm.atomic;

import java.util.concurrent.atomic.AtomicInteger;

/****
 * @Author:刘长柏
 * @Date: 2021-01-05 10:27
 * @Description: 原子类操作
 *****/
public class AtomicIntegerTest {

    static AtomicInteger atomicInteger = new AtomicInteger();

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                public void run() {
                    atomicInteger.incrementAndGet();
                }
            }).start();
        }

        Thread.sleep(1000);
        System.out.println(atomicInteger.get());


        boolean isCasSuccess = atomicInteger.compareAndSet(1, 2);

        System.out.println(isCasSuccess);

    }

}
